# -*- coding:utf-8 -*-
# created on 2017/3/6
# 

from mathsolver.functions.base import *
from mathsolver.functions.base.base import new_latex
from mathsolver.functions.process import ProcessExpression
from sympy import Abs


# 根据向量求投影
class XLGetProjection(BaseFunction):
    def solver(self, *args):
        pro_a = sympify(args[0].value)
        pro_b = sympify(args[1].value)
        known = self.known
        vector_pro = pro_a * pro_b / Abs(pro_a)
        new_vector_pro = ProcessExpression(known).solver(BaseValue(str(vector_pro))).output[0].sympify()
        self.steps.append(["", "%s在%s上的投影是 %s" % (new_latex(pro_b), new_latex(pro_a), new_latex(new_vector_pro))])
        self.output.append(BaseValue(new_vector_pro))
        return self


# 向量投影
class XLProjectionUpdate(BaseFunction):
    """
    已知向量\\vec{a},\\vec{b}满足|{\\vec{a}}|=1,\\vec{a}⊥\\vec{b},则向量\\vec{a}-2\\vec{b}在向量-\\vec{a}方向上的投影为( )
    """
    def solver(self, *args):
        if isinstance(args[0], BaseVector):
            vector_a = sympify(args[0].value)
        else:
            vector_a = args[0].sympify()
        if isinstance(args[1], BaseVector):
            vector_b = sympify(args[1].value)
        else:
            vector_b = args[1].sympify()
        projection = vector_a * vector_b / Abs(vector_a)
        self.steps.append(["", "%s在%s上的投影为: %s" % (new_latex(vector_a), new_latex(vector_b), new_latex(projection))])
        self.output.append(BaseValue(projection))
        self.label.add("求向量的投影")
        return self




